#pragma once

#include <functional>
#include <vector>
#include <string>
#include "LogMessage.hpp"

typedef std::function<int(int, int)> func;

std::vector<std::pair<char, func>> kv;

class Calculator
{
public:
    Calculator(){}

    Calculator(int x, int y, func fun, int index)
        : _x(x)
        , _y(y)
        , _fun(fun)
        , _index(index)
    {}

    void operator()(const std::string& name)
    {
        // 执行任务
        LogMessage(NORMAL, _F, _L, "%s 执行任务 :: %d %c %d = %d", name.c_str(), _x, kv[_index].first, _y, _fun(_x, _y));
    }

public:
    int _x;
    int _y;
    func _fun;
    int _index;
};

void loadCal()
{
    func MyAdd = [](int x, int y){ return x + y; };
    func MySub = [](int x, int y){ return x - y; };
    func MyMul = [](int x, int y){ return x * y; };
    func MyDiv = [](int x, int y){ return x / y; };

    kv.push_back(std::pair<char, func>('+', MyAdd));
    kv.push_back(std::pair<char, func>('-', MySub));
    kv.push_back(std::pair<char, func>('*', MyMul));
    kv.push_back(std::pair<char, func>('/', MyDiv));
}